import { Component, OnInit, Input } from '@angular/core';
import { NGXLogger } from 'ngx-logger';
import {Avatar} from '../../entity/Avatar';
import {RequestReplyService} from '../../services/request-reply.service'

@Component({
  selector: 'app-avatar',
  templateUrl: './avatar.component.html',
  styleUrls: ['./avatar.component.scss']
})
export class AvatarComponent implements OnInit {
  @Input() avatar: Avatar;

    constructor(
      private log: NGXLogger,
      private requestService: RequestReplyService ) {

      }

  ngOnInit() {
    const avt = this.avatar;
    this.log.debug("loading avatar:", avt);
    if(avt && avt.uin && !avt.url){
      this.requestService.GetUser(avt.uin).subscribe((user) => {
        this.log.debug("user:", user);
        if(user)
          avt.url = user.avatar;
      })

    }
  }

}
